#include <iostream>
#include <map>
#include <algorithm>
#include <stdio.h>

using namespace std;

int hashfun(const char* val, int len) {

    int h = 0;
    int off = 0;
    for (int i = 0; i < len; i++) {
       h = 31*h + val[off++];
    }
   // cout << h<< endl;
    return h;

}

int main() {
    int cases;
    scanf("%d", &cases);
    char s[31];
    gets(s);
    gets(s);
    for (int k = 0; k < cases; k++) {
        map<int,int> m;
        string names[10000];
        int index = 0;
        int count = 0;
        string p;
        int len, hash;
        while (gets(s) != NULL) {
            len = strlen(s);
            if (!len) {
                break;
            }
            count++;
            hash = hashfun(s, len);
            if(m[hash] == 0) {
                names[index++] = string(s);
            } //else {
            m[hash]++;
        }
        sort(names, &names[index]);
        const char* c;
        for (int i = 0; i < index; i++ ) {
           //cout << names[i]; // << " " << m[names[k]];
           c = names[i].c_str();
            len = strlen(c);
            hash = hashfun(c, len);
            printf("%s %.4f\n", c, (m[hash] * 100)/(float)count);
        }
        if ((k + 1) != cases) printf("\n");
    }
}
